<%@page import="com.infolab.aims.domain.purchase.PurchaseOrder, java.util.*"%>
<%@ include file="/WEB-INF/views/taglib.jsp" %>


<h3>Month-End Closing Form</h3>	
	<form:form id="form" method="post" modelAttribute="assetModel" cssClass="simpleForm" onsubmit="return beforeSubmit()">
		
	 	<div class="clear" style="height:1px">&nbsp;</div>
		<jsp:include page="/WEB-INF/views/message.jsp"></jsp:include>
		<input type="hidden" id="type" name="type" value="0" />
		<div class="searchCriteria">
	  	<fieldset>
	  		<legend>Month-end Closing: Freeze / Unfreeze</legend>
	  		<p class="clearfix"> 
				<label>Account Month :</label> 
				<input type="text" id="currentMonth" name="currentMonth" value="${currentMonth}" readonly="readonly" />
				<!--  
  				<input id="dateBtn" type="button" class="calendarBtn" />
  				-->
			</p>
			<p class="clearfix"> 
				<label>Department :</label> 
				<select id="departmentId" name="departmentId">
					<option value="">--</option> 
					<c:forEach items="${departments}" var="result" varStatus="status">
						<option <c:if test="${departmentId == result.departmentId}" >  selected="selected" </c:if> value="${result.departmentId}">${result.departmentName}</option>
					</c:forEach>
				</select>
				
			</p>
			<p class="clearfix"> 
				<label>Location :</label> 
				<input type="text" id="location" name="location" value="ALL" readonly="readonly" />
				
			</p>
			<p class="clearfix">
				<label>Closing Status :</label>
				<select id="status" name="status">
					<option value="freeze">Temp Close</option>
					<option value="account">Account Close</option>
				</select>
			</p>
		</fieldset>

 		<span class="right">
		  	<c:if test="${lockFlag == '0'}">
	 			<button id="closeBtn" type="button" class="button positive">Freeze</button>
	 			<input type="hidden" name="freeze" value="1" />
	 		</c:if>
		  	<c:if test="${lockFlag == '1'}">
	 			<button id="closeBtn" type="button" class="button positive">Unfreeze</button>
 				<input type="hidden" name="freeze" value="0" />
	 		</c:if>
			<button type="button" class="button positive" onclick="location.href='<c:url value="/monthEndClosing/search" />'">Back</button>
	 	</span>
	</div>
	
	</form:form>
	

	<script type="text/javascript">
	
		$(function(){
			cal = Calendar.setup({
		          onSelect: function(cal) {cal.hide()},
		          showTime: false
		    });
			cal.manageFields("dateBtn", "currentMonth", globalJsCalMonthFormat);
		});
		
		$("#closeBtn").click(function(){
			$("#form").submit();
		});
		
		
		
		$('#departmentId').change(function(){
			window.location='<c:url value="/monthEndClosing/create?status=freeze" />&departmentId='+$(this).val();
		});
		
		$('#status').change(function(){
			if($(this).val()=='freeze'){
				window.location='<c:url value="/monthEndClosing/create?status=freeze" />';
			}else{
				window.location='<c:url value="/monthEndClosing/create?status=account" />';
			}
		});
		
		function beforeSubmit(){
			if($('#departmentId').val()==""){
				alert("Sorry, you need select a department first.");
				return false;
			}
			return true;
		}
		
	</script>
